package com.cdp.web.controller.system;

import com.cdp.common.core.domain.AjaxResult;
import com.cdp.common.core.domain.entity.SysEfficiencyAgent;
import com.cdp.system.dto.SysEfficiencyAgentDTO;
import com.cdp.system.service.ISysEfficiencyAgentService;
import com.cdp.system.vo.IdsVO;
import com.cdp.system.vo.SandFineneVO;
import com.cdp.system.vo.SysEfficiencyAgentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */

@RestController
@RequestMapping("/system/efficiencyAgent")
public class SysEfficiencyAgentController {

    @Autowired
    private ISysEfficiencyAgentService sysEfficiencyAgent;

    /**
     * 查询增效剂集合
     *
     * @return
     */
    @GetMapping("listEfficiencyAgent")
    public AjaxResult listEfficiencyAgents() {
        List<SysEfficiencyAgent> sysEfficiencyAgentList = sysEfficiencyAgent.listefficiencyAgents();
        return AjaxResult.success(sysEfficiencyAgentList);
    }


    /**
     * 增效剂迷糊查询
     */

    @PostMapping("listMistedEfficiencyAgents")
    public AjaxResult listMistedEfficiencyAgents(@RequestBody SysEfficiencyAgentDTO sysEfficiencyAgentDTO) {

        List<SysEfficiencyAgentVO> sysEfficiencyAgentList = sysEfficiencyAgent.listMistedEfficiencyAgents(sysEfficiencyAgentDTO);

        return AjaxResult.success(sysEfficiencyAgentList);
    }







    /**
     * 增效剂id模糊查询
     */
    @GetMapping("/queryEfficiencyAgentsIdsById")
    public AjaxResult queryEfficiencyAgentsIdsById(@RequestParam(required = false) Integer id) {
        // 获取 IdsVO 对象
        IdsVO idsVO = sysEfficiencyAgent.queryEfficiencyAgentsIdsById(id);

        // 将 ids 列表转换为所需格式
        List<SandFineneVO> sandFinenessVOList = idsVO.getIds().stream()
                .map(idValue -> {
                    SandFineneVO vo = new SandFineneVO();
                    vo.setValue(String.valueOf(idValue)); // 将 Integer 转为 String
                    vo.setLabel(String.valueOf(idValue));
                    return vo;
                })
                .collect(Collectors.toList());
        // 返回包装好的结果
        return AjaxResult.success(sandFinenessVOList);
    }














}
